home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / utilitys / 57 / scanfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-10-19  |  1.4 KB  |  46 lines

  1. /*******************************************************************/
  2. /*  This program will read in a text file and compute the number   */
  3. /*  of alpha, numeric, blank, or other characters found.           */
  4. /*******************************************************************/
  5.  
  6. /*  Compile and link this program, then rename it to SCANFILE.TOS  */
  7.  
  8. #include "stdio.h"
  9.  
  10. main()
  11. {
  12.    FILE  *input_file;
  13.    char  input_name[15];
  14.    int   count = 0,charin;
  15.    int   digit = 0,other = 0;
  16.    int   alpha = 0,space = 0;
  17.  
  18.  
  19.    printf("File Scanning Program\n");
  20.    printf("\nThis program will count occurrences of digits,\n");
  21.    printf("alphabetic characters, blanks in a text file\n");
  22.    printf("\n");
  23.    printf("Enter the name of the input file : ");
  24.    scanf("%s",input_name);
  25.    input_file = fopen(input_name, "r");
  26.    if (input_file == NULL) {
  27.        printf("Cannot open input file.\n");
  28.        exit(0);
  29.    }
  30.    for(count=0;;++count) {
  31.       charin = getc(input_file);
  32.       if ((charin >= 'A') && (charin <= 'z')) alpha++;
  33.       else if ((charin >= '0') && (charin <='9')) digit++;
  34.       else if (charin == ' ') space++;
  35.       else if (charin == EOF) break;
  36.       else other++;
  37.    }
  38.    printf("\nSUMMARY\n");
  39.    printf("There were %d digits entered\n",digit);
  40.    printf("Along with %d alphabetic characters,\n",alpha);
  41.    printf("%d whitespace characters,\n",space);
  42.    printf("and %d other characters.\n",other);
  43.    gemdos(0x1);
  44. }
  45.  
  46.